package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.append.CreateUserAppendBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.UserAppendDao;
import com.zhuss.core.db.entity.UserAppend;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;


/**
 * @description: 用户关注、点赞创建
 * @author: zhushanshuo
 * @create: Fri Jul 03 20:49:22 CST 2020
 **/
@Component("userAppendCreate")
public class UserAppendCreate extends AbstractProcessor<Object, CreateUserAppendBo> implements Processor<Object, CreateUserAppendBo> {

    @Autowired
    private UserAppendDao userAppendDao;
    
    @Autowired
	@Qualifier("userAppendRead")
	private UserAppendRead userAppendRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreateUserAppendBo bo) throws WpsException {
    	// TODO 创建 用户关注、点赞 校验， 请补充
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreateUserAppendBo param) {
    	UserAppend record = new UserAppend();
    	record.setType(param.getType());
    	record.setUserId(param.getUserId());
    	record.setTargetUserId(param.getTargetUserId());
    	record.setContent(param.getContent());
    	record.setArea(param.getArea());
    	record.setSort(param.getSort());

    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	userAppendDao.create(record);
    	param.setTargetId(record.getUserAppendId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateUserAppendBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.黑名单.key());
    	record.setAction(LogActionEnum.用户关注创建.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(param.getUserId() + "关注" + param.getTargetUserId());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
